<?php

namespace App\Http\Requests\Admin\AdminGoods;

use App\Http\Requests\Request;

class GoodsUpdateRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * 验证规则
     *
     * @return array
     */
    public function rules()
    {

        $rules = [
            'cat_id' => 'required|exists:category,cat_id',
            'goods_name' => 'required',
            'goods_sn' => 'required',
            //'goods_bar_code' => 'required',
            'brand_id'=>'required|exists:brand,brand_id',
            'market_price'=>'required',
            'shop_price'=>'required',
            'shop_id'=>'required|exists:shop,id',
            'market_price'=>'numeric',
            'shop_price'=>'numeric',
        ];


        $eorder =  [
//            'ieType' => 'required|in:I,E',
//            'stockFlag' => 'required|in:1,2',
//            'batchNumbers' => 'required',
//            'tradeCountryCiq' => 'required',
//            'tradeCountryCus' => 'required',
//            'packageTypeCiq' => 'required',
//            'packageTypeCus' => 'required',
//            'currencyCiq' => 'required',
//            'currencyCus' => 'required',
//            'unitCiq' => 'required',
//            'unitCus' => 'required',
//            'originCountryCiq' => 'required',
//            'originCountryCus' => 'required',
//            'weight' => 'required',
//            'transportationWay' => 'required',
//            'shipCode' => 'required',
        ];

        $type = $this->get('type');

        if ($type){
            $rules = array_merge($rules,$eorder);
        }


        return $rules;


    }

    /**
     * 验证信息
     * @return array
     */

    public function messages()
    {
        return [
            'cat_id.required' => '请选择商品分类',
            'goods_name.required'=>'请填写商品名称',
            'goods_sn.required'=>'请填写商品编号',
            //'goods_bar_code.required'=>'请填写商品条形码',
            'brand_id.required'=>'请选择品牌ID',
            'market_price.required'=>'请填写市场价',
            'shop_price.required'=>'请填写商城价格',
            'shop_id.required'=>'请选择商铺',

            'cat_id.exists' => '所选商品分类不存在',
            'brand_id.exists' => '所选品牌不存在',
            'market_price.numeric'=>'市场价必须为数字',
            'shop_price.numeric'=>'商城价格必须为数字',
            'shop_id.exists' => '所选商铺不存在',

//            'ieType.required' => '请选择进出口标志',
//            'stockFlag.required' => '请选择集货/备货',
//            'batchNumbers.required' => '请填写批次号',
//            'tradeCountryCiq.required' => '请填写贸易国别（检）',
//            'tradeCountryCus.required'=>'请填写贸易国别（关）',
//            'packageTypeCiq.required'=>'请填写包装种类（检）',
//            'packageTypeCus.required'=>'请填写包装种类（关）',
//            'currencyCiq.required' => '请选择币制（检）',
//            'currencyCus.required' => '请选择币制（关）',
//            'unitCiq.required' => '请填写计量单位（检）',
//            'unitCus.required' => '请填写计量单位（关）',
//            'originCountryCiq.required' => '请填写原国产（检）',
//            'originCountryCus.required'=>'请填写原国产（关）',
//            'weight.required'=>'请填写毛重',
//            'transportationWay.required'=>'请选择运输方式（检）',
//            'shipCode.required' => '请选择运输工具（关）',




        ];
    }
}//end class
